/**
 * 
 */
package com.scpii.universal.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.ContentImgDtoForPru;
import com.scpii.universal.hibernate.dao.ContentImgDao;
import com.scpii.universal.hibernate.entity.ContentImgTab;
import com.scpii.universal.service.ContentImgService;

/**
 * genericWeb
 * 
 * @author weny 2012-7-8下午09:39:49
 */
@Service
public class ContentImgServiceImpl extends
		BaseServiceImpl<ContentImgTab, Integer> implements ContentImgService {
    @Resource
	private ContentImgDao contentImgDao;

	@Resource
	public void setBaseDao(ContentImgDao contentImgDao) {
		super.setBaseDao(contentImgDao);
	}

	@Override
	public List<ContentImgTab> getImgListById(Integer intContentId) {
		StringBuffer hql = new StringBuffer("from ContentImgTab t");
		
		hql.append(" where t.intContentId =:intContentId ");			 
		
		hql.append(" and t.intDeleteSign=:intDeleteSign");
		hql.append(" order by t.intOrder asc, t.datUpdateDatetime asc");
//		hql.append(" and t.intType=:intType");
		
		Map<String,Object> argsMap = new HashMap<String,Object>();
		argsMap.put("intContentId", intContentId);
//		argsMap.put("intType", 0);
		argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
		return contentImgDao.hqlGetList(hql.toString(), argsMap);
	}
	
	public List<ContentImgDtoForPru> getImgsInfotById(Integer intContentId) {
		return contentImgDao.getImgsInfoById(intContentId);
	}

	@Override
	public List<ContentImgTab> getImgListByIdImgType(Integer intContentId, Integer intType) {
		StringBuffer hql = new StringBuffer("SELECT * FROM CONTENT_IMG_TAB t");
		hql.append(" WHERE t.INT_CONTENT_ID=:intContentId ");
		hql.append(" AND t.INT_TYPE!=:intType ");
		hql.append(" AND t.INT_DELETE_SIGN=:intDeleteSign");
		hql.append(" ORDER BY t.INT_ORDER ASC, t.DAT_UPDATE_DATETIME ASC");
		
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("intContentId", intContentId);
		argsMap.put("intType", intType);
		argsMap.put("intDeleteSign", GenericConstants.DELETE_SIGN_EXIST);
		
		List<ContentImgTab> contentImgList = this.sqlGetList(hql.toString(), argsMap);
		
		return contentImgList;
	}
}
